using System;
using Android.Graphics;
using Android.Util;
using Android.Views;
using Android.Widget;
using Com.Gcssloop.Widget;
using mb;
using mb.Droid;

namespace libmp
{

    public class MemberCenterView
    {
        static ILog logger = ServiceLocator.Instance.Get<ILog>();

        public static MyFragment CreateFragment()
        {
            return new MyFragment()
            {
                Title = "会员中心",
                    MyOnCreateView = (f, container) => CreateView(f),

            };

        }

        public static View CreateView(MyFragment f)
        {
            var ctx = StartActivity.This;
            LinearLayout FLayout = new LinearLayout(ctx);
            FLayout.Orientation = Orientation.Vertical;
            FLayout.SetBackgroundColor(Color.Rgb(238, 238, 238));

            LinearLayout memberCenterLayoutTop = new LinearLayout(ctx);
            memberCenterLayoutTop.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 120);
            memberCenterLayoutTop.SetGravity(GravityFlags.Center);
            memberCenterLayoutTop.SetBackgroundColor(Color.Rgb(251, 114, 153));

            LinearLayout memberCenterLayoutTopLeft = new LinearLayout(ctx);
            var memberCenterLayoutTopLeftParams = new LinearLayout.LayoutParams(180, LinearLayout.LayoutParams.MatchParent);
            memberCenterLayoutTopLeft.LayoutParameters = memberCenterLayoutTopLeftParams;
            memberCenterLayoutTopLeft.SetVerticalGravity(GravityFlags.CenterVertical);
            var returnImageView = new ImageView(ctx);
            returnImageView.SetImageDrawable(Util.DrawableFromFile("user/Fanhui.png"));
            var returnImageViewParams = new LinearLayout.LayoutParams(40, 40);
            returnImageViewParams.LeftMargin = 10;
            returnImageViewParams.RightMargin = 30;
            returnImageView.LayoutParameters = returnImageViewParams;
            memberCenterLayoutTopLeft.AddView(returnImageView);

            var returnText = new TextView(ctx);
            returnText.Text = "返回";
            returnText.SetTextColor(Color.White);
            returnText.SetTypeface(Typeface.Default, TypefaceStyle.Bold);
            returnText.SetTextSize(ComplexUnitType.Pt, 7);
            memberCenterLayoutTopLeft.AddView(returnText);
            memberCenterLayoutTop.AddView(memberCenterLayoutTopLeft);
            memberCenterLayoutTopLeft.Click += (s, e) =>
            {
                logger.Log("返回------------");
                f.FragmentManager.PopBackStack();
            };

            LinearLayout memberCenterLayoutTopCentar = new LinearLayout(ctx);
            memberCenterLayoutTopCentar.LayoutParameters = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MatchParent, 1);
            memberCenterLayoutTopCentar.SetGravity(GravityFlags.Center);
            var registeredTopCenterText = new TextView(ctx);
            registeredTopCenterText.Text = "会员中心";
            registeredTopCenterText.SetTextColor(Color.White);
            registeredTopCenterText.SetTypeface(Typeface.Default, TypefaceStyle.Bold);
            registeredTopCenterText.SetTextSize(ComplexUnitType.Pt, 9);
            memberCenterLayoutTopCentar.AddView(registeredTopCenterText);
            memberCenterLayoutTop.AddView(memberCenterLayoutTopCentar);

            LinearLayout memberCenterLayoutTopRight = new LinearLayout(ctx);
            memberCenterLayoutTopRight.LayoutParameters = new LinearLayout.LayoutParams(190, LinearLayout.LayoutParams.MatchParent);
            memberCenterLayoutTopRight.SetGravity(GravityFlags.Center);
            var ForgetPassText = new TextView(ctx);
            // ForgetPassText.Text = "忘记密码";
            ForgetPassText.SetTextColor(Color.White);
            ForgetPassText.SetTypeface(Typeface.Default, TypefaceStyle.Bold);
            ForgetPassText.SetTextSize(ComplexUnitType.Pt, 7);
            memberCenterLayoutTopRight.AddView(ForgetPassText);
            memberCenterLayoutTop.AddView(memberCenterLayoutTopRight);
            FLayout.AddView(memberCenterLayoutTop);

            var scv = new ScrollView(ctx);
            scv.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            LinearLayout memberCenterLayoutInformation = new LinearLayout(ctx);
            scv.AddView(memberCenterLayoutInformation);
            memberCenterLayoutInformation.Orientation = Orientation.Vertical;
            memberCenterLayoutInformation.SetBackgroundColor(Color.Rgb(238, 238, 238));
            memberCenterLayoutInformation.LayoutParameters = new ScrollView.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            LinearLayout memberCenterLayoutCenter = new LinearLayout(ctx);
            var memberCenterLayoutCenterParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 780);
            memberCenterLayoutCenter.LayoutParameters = memberCenterLayoutCenterParams;
            memberCenterLayoutCenter.SetPadding(40, 20, 40, 0);
            memberCenterLayoutCenter.Orientation = Orientation.Vertical;
            memberCenterLayoutCenter.SetBackgroundColor(Color.White);
            memberCenterLayoutCenterView(memberCenterLayoutCenter);
            filletView(memberCenterLayoutCenter);
            memberPrivilege(memberCenterLayoutCenter);
            memberCenterLayoutInformation.AddView(memberCenterLayoutCenter);

            LinearLayout memberCenterLayoutBottom = new LinearLayout(ctx);
            var memberCenterLayoutBottomParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 1100);
            memberCenterLayoutBottomParams.TopMargin = 20;
            memberCenterLayoutBottom.LayoutParameters = memberCenterLayoutBottomParams;
            memberCenterLayoutBottom.SetPadding(40, 20, 40, 0);
            memberCenterLayoutBottom.SetBackgroundColor(Color.White);
            memberCenterLayoutBottom.Orientation = Orientation.Vertical;
            purchaseMemberView(memberCenterLayoutBottom);
            memberCenterLayoutInformation.AddView(memberCenterLayoutBottom);

            FLayout.AddView(scv);
            return FLayout;
        }

        static void memberCenterLayoutCenterView(LinearLayout memberCenterLayoutCenter)
        {
            var ctx = StartActivity.This;

            LinearLayout membershipLayout = new LinearLayout(ctx);
            membershipLayout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 100);
            membershipLayout.SetVerticalGravity(GravityFlags.CenterVertical);
            membershipLayout.Orientation = Orientation.Horizontal;

            var membershipTypeText = new TextView(ctx);
            membershipTypeText.Text = "至尊会员：";
            membershipTypeText.SetTypeface(Typeface.Default, TypefaceStyle.Bold);
            membershipTypeText.SetTextSize(ComplexUnitType.Pt, 6);
            membershipTypeText.SetTextColor(Color.Black);
            membershipLayout.AddView(membershipTypeText);
            var membershipPrivilegeText = new TextView(ctx);
            membershipPrivilegeText.Text = "独享4大特权，无限看电影!";
            membershipPrivilegeText.SetTextSize(ComplexUnitType.Pt, 6);
            membershipPrivilegeText.SetTextColor(Color.Black);
            membershipLayout.AddView(membershipPrivilegeText);

            memberCenterLayoutCenter.AddView(membershipLayout);
        }

        static void filletView(LinearLayout memberCenterLayoutCenter)
        {
            var ctx = StartActivity.This;
            LinearLayout filletLayout = new LinearLayout(ctx);
            filletLayout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 400);
            filletLayout.SetVerticalGravity(GravityFlags.CenterVertical);

            RCRelativeLayout layoutBalanceRCLayout = new RCRelativeLayout(ctx);
            var layoutBalanceRCLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 400);
            layoutBalanceRCLayout.LayoutParameters = layoutBalanceRCLayoutParams;
            layoutBalanceRCLayout.SetRadius(20);

            LinearLayout informationlayout = new LinearLayout(ctx);
            var informationlayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
            informationlayout.LayoutParameters = informationlayoutParams;
            informationlayout.SetBackgroundColor(Color.Rgb(251, 114, 153));
            layoutBalanceRCLayout.AddView(informationlayout);

            filletLayout.AddView(layoutBalanceRCLayout);
            memberCenterLayoutCenter.AddView(filletLayout);
        }

        static void memberPrivilege(LinearLayout memberCenterLayoutCenter)
        {
            var ctx = StartActivity.This;
            LinearLayout memberPrivilegeLayout = new LinearLayout(ctx);
            memberPrivilegeLayout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 250);
            memberPrivilegeLayout.SetPadding(20, 20, 20, 0);
            memberPrivilegeLayout.SetVerticalGravity(GravityFlags.CenterVertical);
            memberPrivilegeLayout.Orientation = Orientation.Horizontal;
            //左
            var memberPrivilegeLayoutLeft = new LinearLayout(ctx);
            var memberPrivilegeLayoutLeftParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MatchParent, 1);
            memberPrivilegeLayoutLeftParams.RightMargin = 40;
            memberPrivilegeLayoutLeft.LayoutParameters = memberPrivilegeLayoutLeftParams;
            memberPrivilegeLayoutLeft.Orientation = Orientation.Vertical;

            RCRelativeLayout memberPrivilegeRCLayoutLeftTop = new RCRelativeLayout(ctx);
            var memberPrivilegeRCLayoutLeftTopParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 100);
            memberPrivilegeRCLayoutLeftTop.LayoutParameters = memberPrivilegeRCLayoutLeftTopParams;
            memberPrivilegeRCLayoutLeftTop.SetRadius(20);
            memberPrivilegeRCLayoutLeftTop.StrokeColor = Color.Rgb(169, 169, 169);
            memberPrivilegeRCLayoutLeftTop.StrokeWidth = 2;

            LinearLayout informationlayoutLeftTop = new LinearLayout(ctx);
            var informationlayoutLeftTopParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
            informationlayoutLeftTop.LayoutParameters = informationlayoutLeftTopParams;
            informationlayoutLeftTop.SetGravity(GravityFlags.Center);

            var informationlayoutLeftTopText = new TextView(ctx);
            informationlayoutLeftTopText.Text = "无限播放";
            informationlayoutLeftTopText.SetTextColor(Color.Black);
            informationlayoutLeftTopText.SetTextSize(ComplexUnitType.Pt, 6);
            informationlayoutLeftTop.AddView(informationlayoutLeftTopText);
            memberPrivilegeRCLayoutLeftTop.AddView(informationlayoutLeftTop);
            memberPrivilegeLayoutLeft.AddView(memberPrivilegeRCLayoutLeftTop);

            RCRelativeLayout memberPrivilegeRCLayoutLeftBottom = new RCRelativeLayout(ctx);
            var memberPrivilegeRCLayoutLeftBottomParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 100);
            memberPrivilegeRCLayoutLeftBottomParams.TopMargin = 20;
            memberPrivilegeRCLayoutLeftBottom.LayoutParameters = memberPrivilegeRCLayoutLeftBottomParams;
            memberPrivilegeRCLayoutLeftBottom.SetRadius(20);
            memberPrivilegeRCLayoutLeftBottom.StrokeColor = Color.Rgb(169, 169, 169);
            memberPrivilegeRCLayoutLeftBottom.StrokeWidth = 2;

            LinearLayout informationlayoutLeftBottom = new LinearLayout(ctx);
            var informationlayoutLeftBottomParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
            informationlayoutLeftBottom.LayoutParameters = informationlayoutLeftBottomParams;
            informationlayoutLeftBottom.SetGravity(GravityFlags.Center);

            var informationlayoutLeftBottomText = new TextView(ctx);
            informationlayoutLeftBottomText.Text = "无广告";
            informationlayoutLeftBottomText.SetTextColor(Color.Black);
            informationlayoutLeftBottomText.SetTextSize(ComplexUnitType.Pt, 6);
            informationlayoutLeftBottom.AddView(informationlayoutLeftBottomText);
            memberPrivilegeRCLayoutLeftBottom.AddView(informationlayoutLeftBottom);
            memberPrivilegeLayoutLeft.AddView(memberPrivilegeRCLayoutLeftBottom);

            memberPrivilegeLayout.AddView(memberPrivilegeLayoutLeft);
            //右
            var memberPrivilegeLayoutRight = new LinearLayout(ctx);
            var memberPrivilegeLayoutRightParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MatchParent, 1);
            memberPrivilegeLayoutRightParams.LeftMargin = 40;
            memberPrivilegeLayoutRight.LayoutParameters = memberPrivilegeLayoutRightParams;
            memberPrivilegeLayoutRight.Orientation = Orientation.Vertical;

            RCRelativeLayout memberPrivilegeRCLayoutRightTop = new RCRelativeLayout(ctx);
            var memberPrivilegeRCLayoutRightTopParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 100);
            memberPrivilegeRCLayoutRightTop.LayoutParameters = memberPrivilegeRCLayoutRightTopParams;
            memberPrivilegeRCLayoutRightTop.SetRadius(20);
            memberPrivilegeRCLayoutRightTop.StrokeColor = Color.Rgb(169, 169, 169);
            memberPrivilegeRCLayoutRightTop.StrokeWidth = 2;

            LinearLayout informationlayoutRightTop = new LinearLayout(ctx);
            var informationlayoutRightTopParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
            informationlayoutRightTop.LayoutParameters = informationlayoutRightTopParams;
            informationlayoutRightTop.SetGravity(GravityFlags.Center);

            var informationlayoutRightTopText = new TextView(ctx);
            informationlayoutRightTopText.Text = "无限缓存";
            informationlayoutRightTopText.SetTextColor(Color.Black);
            informationlayoutRightTopText.SetTextSize(ComplexUnitType.Pt, 6);
            informationlayoutRightTop.AddView(informationlayoutRightTopText);
            memberPrivilegeRCLayoutRightTop.AddView(informationlayoutRightTop);
            memberPrivilegeLayoutRight.AddView(memberPrivilegeRCLayoutRightTop);

            RCRelativeLayout memberPrivilegeRCLayoutRightBottom = new RCRelativeLayout(ctx);
            var memberPrivilegeRCLayoutRightBottomParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 100);
            memberPrivilegeRCLayoutRightBottomParams.TopMargin = 20;
            memberPrivilegeRCLayoutRightBottom.LayoutParameters = memberPrivilegeRCLayoutRightBottomParams;
            memberPrivilegeRCLayoutRightBottom.SetRadius(20);
            memberPrivilegeRCLayoutRightBottom.StrokeColor = Color.Rgb(169, 169, 169);
            memberPrivilegeRCLayoutRightBottom.StrokeWidth = 2;

            LinearLayout informationlayoutRightBottom = new LinearLayout(ctx);
            var informationlayoutRightBottomParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
            informationlayoutRightBottom.LayoutParameters = informationlayoutRightBottomParams;
            informationlayoutRightBottom.SetGravity(GravityFlags.Center);

            var informationlayoutRightBottomText = new TextView(ctx);
            informationlayoutRightBottomText.Text = "独享服务器";
            informationlayoutRightBottomText.SetTextColor(Color.Black);
            informationlayoutRightBottomText.SetTextSize(ComplexUnitType.Pt, 6);
            informationlayoutRightBottom.AddView(informationlayoutRightBottomText);
            memberPrivilegeRCLayoutRightBottom.AddView(informationlayoutRightBottom);
            memberPrivilegeLayoutRight.AddView(memberPrivilegeRCLayoutRightBottom);
            memberPrivilegeLayout.AddView(memberPrivilegeLayoutRight);

            memberCenterLayoutCenter.AddView(memberPrivilegeLayout);

        }

        static void purchaseMemberView(LinearLayout memberCenterLayoutBottom)
        {
            var ctx = StartActivity.This;

            LinearLayout purchaseMemberLayout = new LinearLayout(ctx);
            purchaseMemberLayout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 100);
            purchaseMemberLayout.SetVerticalGravity(GravityFlags.CenterVertical);
            purchaseMemberLayout.Orientation = Orientation.Horizontal;

            var purchaseMemberText = new TextView(ctx);
            purchaseMemberText.Text = "购买会员：";
            purchaseMemberText.SetTypeface(Typeface.Default, TypefaceStyle.Bold);
            purchaseMemberText.SetTextSize(ComplexUnitType.Pt, 6);
            purchaseMemberText.SetTextColor(Color.Black);
            purchaseMemberLayout.AddView(purchaseMemberText);
            var purchaseMemberViewRightText = new TextView(ctx);
            purchaseMemberViewRightText.Text = "一次性购买独享超低折扣";
            purchaseMemberViewRightText.SetTextSize(ComplexUnitType.Pt, 6);
            purchaseMemberViewRightText.SetTextColor(Color.Rgb(105, 105, 105));
            purchaseMemberLayout.AddView(purchaseMemberViewRightText);
            memberCenterLayoutBottom.AddView(purchaseMemberLayout);

            LinearLayout membershipTypesLayout = new LinearLayout(ctx);
            membershipTypesLayout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
            membershipTypesLayout.Orientation = Orientation.Vertical;
            // membershipTypesLayout.SetBackgroundColor(Color.Black);

            membershipTypesList(membershipTypesLayout);
            memberCenterLayoutBottom.AddView(membershipTypesLayout);
        }

        static void membershipTypesList(LinearLayout membershipTypesLayout)
        {
            var btnPicWidth = 50;
            var btnPicHeight = 50;

            var membershipInfoArray = new String[][]
            {
                new String[] { "user/Zhou.png", "任性看", "18元/周", "" },
                new String[] { "user/Yue.png", "月度看", "59元/月", "" },
                new String[] { "user/Membershipexpires.png", "季度会员", "138元/季", "" },
                new String[] { "user/Nianduhuiyuan.png", "年度会员", "498元/年", "" },
                new String[] { "user/Vip.png", "至尊VIP服务", "1588元/年", "人工服务，独享单台服务器，永不卡顿" }
            };

            var ctx = StartActivity.This;
            for (int i = 0; i < membershipInfoArray.Length; i++)
            {
                var layoutOperationInfo = new LinearLayout(ctx);
                // layoutOperationInfo.SetBackgroundColor(Color.Red);
                layoutOperationInfo.Orientation = Orientation.Horizontal;

                RCRelativeLayout membershipTypesRCLayout = new RCRelativeLayout(ctx);
                if (membershipInfoArray[i][3].Length > 0)
                {
                    var membershipTypesVIPRCLayoutParams = new LinearLayout.LayoutParams(0, 210, 1.0f);
                    membershipTypesVIPRCLayoutParams.TopMargin = 20;
                    membershipTypesRCLayout.LayoutParameters = membershipTypesVIPRCLayoutParams;
                }
                else
                {
                    var membershipTypesRCLayoutParams = new LinearLayout.LayoutParams(0, 160, 1.0f);
                    membershipTypesRCLayoutParams.TopMargin = 20;
                    membershipTypesRCLayout.LayoutParameters = membershipTypesRCLayoutParams;
                }

                membershipTypesRCLayout.SetRadius(20);
                membershipTypesRCLayout.StrokeColor = Color.Rgb(169, 169, 169);
                membershipTypesRCLayout.StrokeWidth = 2;

                var layoutOperationLeft = new LinearLayout(ctx);
                layoutOperationLeft.Orientation = Orientation.Horizontal;
                layoutOperationLeft.SetVerticalGravity(GravityFlags.CenterVertical);
                layoutOperationLeft.SetHorizontalGravity(GravityFlags.Left);
                var layoutOperationLeftParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
                layoutOperationLeft.LayoutParameters = layoutOperationLeftParams;
                // layoutOperationLeft.SetBackgroundColor(Color.Red);
                var layoutOperationLeftPic = new LinearLayout(ctx);
                var layoutOperationLeftPicParams = new LinearLayout.LayoutParams(btnPicWidth + 10, btnPicHeight + 10);
                layoutOperationLeftPicParams.LeftMargin = 20;
                layoutOperationLeftPic.LayoutParameters = layoutOperationLeftPicParams;
                var OperationLeftPic = new ImageView(ctx);
                OperationLeftPic.SetImageDrawable(Util.DrawableFromFile(membershipInfoArray[i][0]));
                var LayoutParametersParams = new LinearLayout.LayoutParams(btnPicWidth, btnPicHeight);
                LayoutParametersParams.TopMargin = 5;
                OperationLeftPic.LayoutParameters = LayoutParametersParams;
                layoutOperationLeftPic.AddView(OperationLeftPic);
                layoutOperationLeft.AddView(layoutOperationLeftPic);
                var layoutOperationLeftText = new LinearLayout(ctx);
                layoutOperationLeftText.SetVerticalGravity(GravityFlags.CenterVertical);
                var layoutOperationLeftTextParams = new LinearLayout.LayoutParams(800, LinearLayout.LayoutParams.MatchParent);
                layoutOperationLeftTextParams.LeftMargin = 20;
                layoutOperationLeftText.LayoutParameters = layoutOperationLeftTextParams;
                layoutOperationLeftText.Orientation = Orientation.Vertical;
                var OperationLeftTopText = new TextView(ctx);
                OperationLeftTopText.Text = membershipInfoArray[i][1];
                OperationLeftTopText.SetTextColor(Color.Black);
                layoutOperationLeftText.AddView(OperationLeftTopText);
                if (membershipInfoArray[i][3].Length > 0)
                {
                    var OperationLeftCenterText = new TextView(ctx);
                    OperationLeftCenterText.Text = membershipInfoArray[i][3];
                    OperationLeftCenterText.SetTextColor(Color.Rgb(105, 105, 105));
                    layoutOperationLeftText.AddView(OperationLeftCenterText);
                    var OperationLeftBottomText = new TextView(ctx);
                    OperationLeftBottomText.Text = membershipInfoArray[i][2];
                    OperationLeftBottomText.SetTextColor(Color.Rgb(105, 105, 105));
                    layoutOperationLeftText.AddView(OperationLeftBottomText);
                }
                else
                {
                    var OperationLeftBottomText = new TextView(ctx);
                    OperationLeftBottomText.Text = membershipInfoArray[i][2];
                    OperationLeftBottomText.SetTextColor(Color.Rgb(105, 105, 105));
                    layoutOperationLeftText.AddView(OperationLeftBottomText);

                }
                layoutOperationLeft.AddView(layoutOperationLeftText);
                membershipTypesRCLayout.AddView(layoutOperationLeft);
                layoutOperationInfo.AddView(membershipTypesRCLayout);
                membershipTypesLayout.AddView(layoutOperationInfo);
            }
        }
    };
}